@isTest
private class HelloWorldTestClass {

	//TODO: Create a test method
	static testMethod void helloWorldTest(){

		// TODO: Instantiate a positions list
		// User adminuser = [SELECT id from User where alias = 'システム'];
		User adminuser = [SELECT id from User limit 1];

		// TODO: Create a for loop to create 20 new positions with unique names and descrptions
		List<Position__c> positions = new List<Position__c>();
		for (Integer i=0; i < 20; i++){
			Position__c p = new Position__c();
			p.Name = 'testName' + i;
			p.Job_Description__c = 'testDescription' + i;
			p.Hiring_Manager__c= adminuser.id;
			positions.add(p);
		}

		//TODO: Wrap the following section in a try block
		try{
			Test.starttest();

			System.debug('Attempting to insert positions');
			//TODO: Insert Positions
			Insert positions;
			System.debug('Insert complete');

			// refresh the Position list to include the Hello__c field after the insert
			Map<ID,Position__c> positionMap = new Map<ID,Position__c>(positions);

			//TODO: Create a position map to hold position IDs
			//TODO: Write a SOQL statement to retrieve id, name and Hello_c into positions based on the IDs in the position map
			positions = [select id, name, Hello__c, Job_Description__c from Position__c where id IN :positionMap.keySet()];

			//TODO: Write a loop to iterate through the positions object
			Integer i = 0;
			for(Position__c position:positions){

				//TODO: Inside the loop: ensure position id is not null and hello field contains 'World'
				System.assertNotEquals(position.id, null);
				//TODO: Inside the loop: write position id, name and Hello__c value to the debug log
				System.assertEquals(position.Hello__c, 'World');


				System.assertEquals(position.name, 'testName' + i);
				System.assertEquals(position.Job_Description__c, 'testDescription' + i);

				System.debug('position.id=' + position.id);
				System.debug('position.name=' + position.name);
				System.debug('position.Job_Description__c=' + position.Job_Description__c);
				System.debug('position.Hello__c=' + position.Hello__c);

				i++;
			}
		}
		catch (System.Dmlexception e){

			//TODO: Wrap the following section in a catch block
			System.debug('We caught a DML exception: ' + e.getDmlMessage(0));
		}
	}

}